/-boot
/-docs
/-editor
/-files
/-files-old
/-imports
/-layout
/-shell
/-storage ...
/-storage/attached ...
/-storage/attached/api
/-storage/attached/dom
/-storage/attached/indexedDB ...
DetectStorage.ts
FileData.ts
LoadStorage.ts
MetadataData.ts
StorageAccess.ts
StorageDetect.ts
UpdateStorage.ts
functions.ts
/-storage/attached/localStorage
/-storage/attached/webSQL
/-tests
/-tests/files
/-tests/storage
/-tests/storage/attached
AttachedStorageTests.ts
AttachedStorageTestsNew.ts
DomStorageTests.ts
IndexedDBStorageTests.ts
LocalStorageStorageTests.ts
WebSQLStorageTests.ts
TestCase.html
TestCase.ts
TestPage.css
TestPage.html
TestPage.ts
_sampleTests.ts
teapo-tests.html
teapo-tests.ts
/-typings
Dom.ts
TypeScriptService.ts
functions.ts
ko.ts
nteapo.html
persistence.api.ts
persistence.ts
shell.ts
teapo.html
teapo.ts
try.html
try.js
xxxxxxxxxx
      var metadataData = { property: 'editedUTC', value: now };
 
1
module teapo.storage.attached.indexedDB {
2
​
3
  export class StorageAccess implements attached.StorageAccess {
4
​
5
    constructor(private _db: IDBDatabase) {
6
    }
7
​
8
    update(
9
      byFullPath: PropertiesByFullPath,
10
      timestamp: number,
11
      callback: (error: Error) => void): void {
12
​
13
      var transaction = this._db.transaction(['files', 'metadata'], 'readwrite');
14
      transaction.onerror = (errorEvent) => callback(wrapErrorEvent(errorEvent, 'update: transaction'));
15
      var filesStore = transaction.objectStore('files');
16
      
17
      var outstandingRequests = 1;
18
​
19
      function oneError(errorEvent: ErrorEvent, moreDescription) {
20
        if (!outstandingRequests) return;
21
​
22
        outstandingRequests = 0;
23
        callback(wrapErrorEvent(errorEvent, moreDescription));
24
      }
25
​
26
      function oneCompleted() {
27
        if (!outstandingRequests) return;
28
​
29
        outstandingRequests--;
30
        callback(null);
31
      }
32
​
33
      for (var fullPath in byFullPath) if (byFullPath.hasOwnProperty(fullPath)) {
34
​
35
        var pbag = byFullPath[fullPath];
36
​
37
        if (!pbag) {
38
          var deleteRequest = filesStore['delete'](fullPath);
39
          outstandingRequests++;
40
​
41
          deleteRequest.onerror = (errorEvent) => oneError(errorEvent, 'update: objectStore(files).delete(' + fullPath+')');
42
          deleteRequest.onsuccess = (event) => {
43
            oneCompleted();
44
          };
45
        }
46
        else {
47
          var getRequest = filesStore.get(fullPath);
48
          outstandingRequests++;
49
​
50
          getRequest.onerror = (errorEvent) => oneError(errorEvent, 'update: objectStore(files).delete(' + fullPath + ')');
51
          getRequest.onsuccess = (event) => {
52
​
53
            var fileData: FileData = getRequest.result || { path: fullPath, properties: {} };
54
​
55
            var properties = fileData.properties || (fileData.properties = {});
56
            for (var p in pbag) if (pbag.hasOwnProperty(p)) {
57
              var v = pbag[p];
58
              if (v === null || typeof v === 'undefined')
59
                delete properties[p];
60
              else
61
                properties[p] = v;
62
            }
63
​
64
            var putFile = filesStore.put(fileData);
65
            getRequest.onerror = (errorEvent) => oneError(errorEvent, 'update: objectStore(files).put(' + fullPath + ')');
66
            putFile.onsuccess = (event) =>
67
              this._updateEditedUTC(
68
                timestamp,
69
                transaction,
70
                (errorEvent) => callback(wrapErrorEvent(errorEvent, 'update: _updateEditedUTC')));
71
          };
72
        }
73
        
74
      }
75
​
76
      oneCompleted();
77
    }
78
​
79
    read(
80
      fullPath: string,
81
      callback: (error: Error, properties: { [property: string]: string; }) => void): void {
82
​
83
      var transaction = this._db.transaction('files');
84
      transaction.onerror = (errorEvent) => callback(wrapErrorEvent(errorEvent, 'read: transaction'), null);
85
      var filesStore = transaction.objectStore('files');
86
      var getRequest = filesStore.get(fullPath);
87
      getRequest.onerror = (errorEvent) => callback(wrapErrorEvent(errorEvent, 'read: get(' + fullPath +')'), null);
39:0